package parser;

%%
%class Lexer
%public
%function next_token
%type Token
%line
%8bit
%eofval{
		return new Token(sym.EOF,yyline,"", "EOF");
%eofval}
%{
	StringBuffer string = new StringBuffer();
%}
%scanerror LexicalError
%{
	public int getLineNumber(){
		return yyline;
	}
%}
DIGIT = [0-9]
UPPER = [A-Z]
LOWER = [a-z]
ALPHA = ({UPPER}|{LOWER}|[_])+
ALPHA_NUMERIC={ALPHA}|{DIGIT}
IDENTIFIER = {LOWER}({ALPHA_NUMERIC})*
CLASS_ID = {UPPER}({ALPHA_NUMERIC})*
NEWLINE=\r|\n|\r\n
WHITE_SPACE_CHAR=[\r\ \t]
STRING_TEXT=([!]|[#-~]|[ ]|\\{WHITE_SPACE_CHAR}+\\)*

%state HEADER
%state DISCLEN
%state REVISION
%state DISCID
%state DTITLE
%state DYEAR
%state DSCID
%state DGENRE
%state TTITLE
%state TITLE_STRING
%state IGNORE
%%


<HEADER>{ 
"xmcd" { return new Token(sym.XMCD,yyline,"#xmcd","XMCD");}
"\t" {}
" " {}
"L" {}
"Track frame offsets:" {}
"\n" {yybegin(YYINITIAL);}
{DIGIT} {}
"Disc length:" {yybegin(DISCLEN);}
"Revision:" {yybegin(REVISION);}
. {}
}
<DISCLEN>{
"\t" {}
" " {}
"L" {}
({DIGIT})+ { return new Token(sym.DISC_LEN,yyline,yytext(),"DISC_LEN");}  
"\n" {yybegin(YYINITIAL);}
"seconds" {}
}
<REVISION>{
"\t" {}
" " {}
({DIGIT})+ { return new Token(sym.REVISION,yyline,yytext(),"REVISION");}  
"\n" {yybegin(YYINITIAL);}
}
<DISCID>{
"\t" {}
" " {}
"," {}
({ALPHA_NUMERIC})+ { return new Token(sym.DISCID,yyline,yytext(),"DISCID");}  
"\n" {yybegin(YYINITIAL);}
}
<DTITLE>{
"\n" {yybegin(YYINITIAL);}
(.)* { return new Token(sym.DTITLE,yyline,yytext(),"DTITLE");}  
}
<DYEAR>{
"\n" {yybegin(YYINITIAL);}
({DIGIT})+ { return new Token(sym.DYEAR,yyline,yytext(),"DYEAR");}  
}
<DGENRE>{
"\n" {yybegin(YYINITIAL);}
(.)+ { return new Token(sym.DGENRE,yyline,yytext(),"DGENRE");}  
}
<TTITLE>{
"\n" {yybegin(YYINITIAL);}
({DIGIT})+ {return new Token(sym.TTITLE_NUM,yyline,yytext(),"TTITLE_NUM");}
"=" {yybegin(TITLE_STRING);}
}
<TITLE_STRING>{
"\n" {yybegin(YYINITIAL);}
(.)+ { return new Token(sym.TTITLE,yyline,yytext(),"TTITLE");}  
}
<IGNORE>{
"\n" {yybegin(YYINITIAL);}
. {}
}
<YYINITIAL>{
"DISCID=" {yybegin(DISCID);}
"#" {yybegin(HEADER);}
"DTITLE=" {yybegin(DTITLE);}
"DYEAR=" {yybegin(DYEAR);}
"DGENRE=" {yybegin(DGENRE);}
"TTITLE" {yybegin(TTITLE);}
"\n" {}
"EXTD=" {yybegin(IGNORE);}
"EXTT"({DIGIT})*"=" {yybegin(IGNORE);}
"PLAYORDER=" {yybegin(IGNORE);}
}
<YYINITIAL> .	{throw new LexicalError("Illegal input: " + yytext(), yyline);}



